<?php
App::uses('AppModel', 'Model');
/**
 * Page Model
 *
 */
class Userpage extends AppModel {


	public $useTable = 'pages';
	public $displayField = 'titulo';

/**
 * Validation rules
 *
 * @var array
 */
	public $validate = array(
		'caminho' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => 'created',
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'texto' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'titulo' => array(
				'notempty' => array(
						'rule' => array('notempty'),
						//'message' => 'Your custom message here',
						//'allowEmpty' => false,
						//'required' => false,
						//'last' => false, // Stop validation after this rule
						//'on' => 'create', // Limit validation to 'create' or 'update' operations
				),
				'unicidade' => array(
						'rule' => array('validate_path'),
						'message' => 'Já existe uma página com o mesmo nome',
						//'allowEmpty' => false,
						'required' => true,
						//'last' => false, // Stop validation after this rule
						//'on' => 'create', // Limit validation to 'create' or 'update' operations
				),
		),
		'menu' => array(
				'boolean' => array(
						'rule' => array('boolean'),
						//'message' => 'Your custom message here',
						//'allowEmpty' => false,
						//'required' => false,
						//'last' => false, // Stop validation after this rule
						//'on' => 'create', // Limit validation to 'create' or 'update' operations
				),
		),
	);
	//TODO DONE nao funciona
	function validate_path($data){
		return $this->isUnique(array('Userpage.caminho' => $this->data['Userpage']['caminho']));
	}
	
	function toAscii($str, $replace=array(), $delimiter='-') {
		return parent::toAscii($str, $replace = '', $delimiter='-');
	}
}
